import { useMemo } from 'react'

function useMeta(fields) {
  if (Object.keys(fields).length === 0) return []
  return useMemo(() => {
    const { row, col } = fields
    const _fields = [...row, ...col].sort((a, b) => a.index - b.index)
    return _fields.map((v) => ({
      field: v.id,
      name: v.title,
      type: v.fieldType,
      format: v.numberFormat || 'auto'
    }))
  }, [fields])
}

export default useMeta
